﻿@{
    ViewBag.Title = "Threads";
    Layout = "~/Views/Shared/Houyun.cshtml";
}


<script>
    //点击加精的信息
    function gaitou(id) {
        var str = "";
        if ($(this).prop("class") == "label label-success") {
            str += "";
        }
        else {
            str += "加精";
        }
        //修改属性
        $.post("/Group/edittopic", { id: id, str: str }, function (data) {
            if (data == "1") {
                location.reload();
            }
        })
    }

    //点击推荐
    function gaitui(id) {
        var str = "";
        if ($(this).prop("class") == "label label-success") {
            str += "";
        }
        else {
            str += "置顶";
        }
        //修改属性
        $.post("/Group/edittopic", { id: id, str: str }, function (data) {
            if (data == "1") {
                location.reload();
            }

        })
    }

    //全选按钮
    $(function () {
        $('#quanxuan').click(function () {
            $('#aticle-table-container input[type="checkbox"]').prop("checked", this.checked);
        });
    })

    //批量
    function alldel() {
        if (confirm('确定批量删除吗？')) {
            //获取选中的id
            var listid = "";
            $('#aticle-table-container :checked').each(function () {
                listid += $(this).val() + ',';
            })
            listid = listid.substr(0, listid.length - 1);
            if (listid == "") {

            }
            //ajax传值进行删除
            $.ajax({
                url: "/Group/DelthreadList",
                type: "post",
                data: { listid: listid },
                success: function (result) {
                    if (result == "1") {
                        alert("删除成功");
                        location.href = "/Group/Threads"

                    }
                }

            })

        }

    }
</script>
<script src="~/Content/js/jquery.twbsPagination.js"></script>

<div class="page-header clearfix">
    <h1 class="pull-left">话题管理</h1>
<div class="pull-right">

       

    </div></div>

<ul class="nav nav-tabs mbm">
    <li>
        <a href="/Group/XGroup">小组管理</a>

    </li>
    <li class="active">
        <a href="/Group/Threads">话题管理</a>
    </li>
</ul>

<form class="form-inline well well-sm" action="/Group/Threads" method="get">

    <div class="form-group">
        <select class="form-control" name="TSTATE">
            <option value="">话题状态</option>
            <option value="1">开启</option>
            <option value="0">关闭</option>
        </select>
    </div>

    <div class="form-group">
        <select class="form-control" name="TATTRIBUTE">
            <option value="">属性</option>
            <option value="置顶">置顶</option>
            <option value="加精">加精</option>
        </select>
    </div>

    <div class="form-group">
        <input class="form-control" type="text" placeholder="所属小组" name="GNAME" value="">
    </div>

    <div class="form-group">
        <input class="form-control" type="text" placeholder="话题名称关键词" name="TTITLE" value="">
    </div>

    <div class="form-group">
        <input class="form-control" type="text" placeholder="创建者" name="Uname" value="">
    </div>

    <button class="btn btn-primary">搜索</button>
</form>
<form method="post" id="thread-form">
    <div class="well" id="aticle-table-container">
        <table class="table table-striped table-hover" id="thread-table">
            <thead>
                <tr>
                    <th nowrap="nowrap"> 编号</th>
                    <th width="30%">名称</th>
                    <th nowrap="nowrap">属性</th>
                    <th nowrap="nowrap">创建者</th>
                    <th nowrap="nowrap">所属小组</th>
                    <th nowrap="nowrap">回复数</th>
                    <th nowrap="nowrap">状态</th>
                    <th width="100px" nowrap="nowrap">操作</th>
                </tr>
            </thead>

            <tbody>
                @{
                    List<LeEdu.MODEL.Topicshi> list_topicshi = ViewBag.topic;
                    foreach (var item in list_topicshi)
                    {
                        <tr id="thread-table-tr-2">
                            <td>
                                <input id="Checkbox1" type="checkbox" value="@item.ID" /> @item.ID
                            </td>
                            <td style="word-break:break-all;">
                                <strong><a target="_blank" href="/Group/SreachTopic/@item.ID">@item.TTITLE</a></strong>
                                @if (item.TSTATE == 0)
                                {
                                    <label class="label label-danger">关闭</label>
                                }
                            </td>

                            <td nowrap="nowrap">

                                <a href="#"><span id="t1" onclick="gaitou(@item.ID)" class="label @(item.TATTRIBUTE.Contains("加精") ? "label-success" : "label-default")">精</span></a>

                                <a href="#"><span id="t2" onclick="gaitui(@item.ID)" class="label @(item.TATTRIBUTE.Contains("置顶") ? "label-success" : "label-default")">顶</span></a>
                            </td>

                            <td>
                                <a target="_blank" href="/my/Index">
                                    @item.Users.Uname
                                </a>
                            </td>

                            <td>
                                <a target="_blank" href="/Group/GroupHomepage/@item.GroupID">
                                    @item.GROUPS.GNAME
                                </a>
                            </td>

                            <td>
                                @item.Reply.Count()
                            </td>

                            <td>
                                @(item.TSTATE == 0 ? "关闭" : "开启")
                            </td>

                            <td>
                                <div class="btn-group">
                                    <a href="#" class="btn btn-default btn-sm">操作</a>
                                    <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li>
                                            @if (item.TSTATE == 0)
                                            {
                                                <a href="/Group/EditTopicState/@item.ID" onclick="return confirm('确认要开启话题吗')">
                                                    <span class="glyphicon glyphicon-ok"></span> 开启话题
                                                </a>
                                            }
                                            else
                                            {
                                                <a href="/Group/EditTopicState/@item.ID" onclick="return confirm('确认要关闭话题吗')">
                                                    <span class="glyphicon glyphicon-remove"></span> 关闭话题
                                                </a>
                                            }

                                        </li>
                                        <li><a href="/Group/DelTopic/@item.ID"><span class="glyphicon glyphicon-trash"></span> 永久删除</a></li>
                                    </ul>
                                </div>
                            </td>

                        </tr>

                    }
                }
            </tbody>
        </table>

        @*分页方法 改进 *@
        <nav class=" text-center">
            <ul id="pagination-demo" class="pagination-sm"></ul>
            <script>
                var count;
                $('#pagination-demo').twbsPagination({
                    totalPages:@ViewData["pageCount"] ,
                    first: "首页",
                    prev: "上一页",
                    next: "下一页",
                    last: "尾页",
                    href: '/Group/Threads/?pageIndex={{pageNumber}}',
                    hrefVariable: '{{pageNumber}}'
                });
            </script>
        </nav>
    </div>
</form>
<div>
    @*-------------------------------------------------------------------------*@

    



    @*---------------------------------------------------------------------------*@
    @*<div style="float:left">
        <a href="/Group/Threads/?pageIndex=1&TSTATE=@(ViewBag.TSTATE)&TATTRIBUTE=@(ViewBag.TATTRIBUTE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&GNAME=@(ViewBag.GNAME)&TTITLE=@(ViewBag.TTITLE)&Uname=@(ViewBag.Uname)" class="btn btn-default">首页</a>
        <a href="/Group/Threads/?pageIndex=@((ViewBag.pageIndex-1)>1?(ViewBag.pageIndex-1):1)&TSTATE=@(ViewBag.TSTATE)&TATTRIBUTE=@(ViewBag.TATTRIBUTE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&GNAME=@(ViewBag.GNAME)&TTITLE=@(ViewBag.TTITLE)&Uname=@(ViewBag.Uname)" class="btn btn-default">上一页</a>&nbsp;
        <span class="btn btn-circle-xs btn-danger ">@ViewBag.pageIndex/@ViewBag.pageCount</span>&nbsp;
        <a href="/Group/Threads/?pageIndex=@((ViewBag.pageIndex+1)<ViewBag.pageCount?(ViewBag.pageIndex+1):ViewBag.pageCount)&TSTATE=@(ViewBag.TSTATE)&TATTRIBUTE=@(ViewBag.TATTRIBUTE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&GNAME=@(ViewBag.GNAME)&TTITLE=@(ViewBag.TTITLE)&Uname=@(ViewBag.Uname)" class="btn btn-default">下一页</a>
        <a href="/Group/Threads/?pageIndex=@ViewBag.pageCount&TSTATE=@(ViewBag.TSTATE)&TATTRIBUTE=@(ViewBag.TATTRIBUTE)&ATTRIBUTE=@(ViewBag.ATTRIBUTE)&GNAME=@(ViewBag.GNAME)&TTITLE=@(ViewBag.TTITLE)&Uname=@(ViewBag.Uname)" class="btn btn-default">尾页</a>
    </div>
    <div style="float:right">
        <form action="/Group/Threads" method="post">
            <input id="Hidden1" type="hidden" name="ColumnssID" value="@ViewBag.ColumnssID" />
            <input id="Hidden1" type="hidden" name="INTITLE" value="@ViewBag.INTITLE" />
            <input id="Hidden1" type="hidden" name="ATTRIBUTE" value="@ViewBag.ATTRIBUTE" />
            <input id="Hidden1" type="hidden" name="INSTATE" value="@ViewBag.INSTATE" />
            <p>
                <span style="">跳转到：</span>
                <input class="inputwidth" type="text" name="pageIndex" id="pageIndex" value="" size="3">
                <input id="Submit1" type="submit" value="GO" />
            </p>
        </form>
    </div>*@


</div>
<div>
    <label class="checkbox-inline">
        <input type="checkbox" data-role="batch-select" id="quanxuan">全选
    </label>
    <input type="hidden" id="batchDeleteThread" value="/admin/group/batchDeleteThread">
    <button id="thread-delete-btn" onclick="alldel()" data-submiting-text="正在删除" type="button" class="btn btn-default btn-sm mlm">删除话题</button>
</div>

<div class="pull-right">

</div>
